package com.ityuwen.mengyagushi.search.listener;

import com.ityuwen.mengyagushi.common.constant.KafkaConstant;
import com.ityuwen.mengyagushi.search.service.SearchService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

@Component
public class SearchListener {

    @Autowired
    private SearchService searchService;

    @KafkaListener(topics = KafkaConstant.QUEUE_ALBUM_UPPER)
    public void upper(String albumId, Acknowledgment ack){
        if (StringUtils.isBlank(albumId)){
            ack.acknowledge();
            return;
        }

        this.searchService.upper(Long.valueOf(albumId));
        ack.acknowledge();
    }

    @KafkaListener(topics = KafkaConstant.QUEUE_ALBUM_LOWER)
    public void lower(String albumId, Acknowledgment ack){
        if (StringUtils.isBlank(albumId)){
            ack.acknowledge();
            return;
        }

        this.searchService.lower(albumId);
        ack.acknowledge();
    }
}
